package org.robert.export_client.excel.builder;

import javax.servlet.http.HttpServletResponse;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * CsvDataRespBuilder:
 *
 * @author zhaoshengtao
 * @date 2024/02/27
 */
public class CsvDataRespBuilder {

    protected OutputStream outputStream;

    protected HttpServletResponse response;

    protected String path;

    protected String fileName = String.valueOf(System.currentTimeMillis());

    protected boolean flag = true;

    public void write(){

        String fileName = "output.csv";
        List<String[]> data = new ArrayList<>();
        try (FileWriter writer = new FileWriter(fileName)) {
            for (String[] rowData : data) {
                writer.append(String.join(",", rowData));
                writer.append("\n");
            }
            System.out.println("CSV file was created successfully.");
        } catch (IOException e) {
            System.out.println("Error while creating CSV file: " + e.getMessage());
        }

    }

}
